﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SlackOff
{
    public class WorkingTimeState : ITimeState
    {
        private ITimeStateContext context;
        private readonly TimeLeft timeLeft;
        public WorkingTimeState(ITimeStateContext context)
            : this(context, context.Options.WorkingTimeMinutes)
        {
        }

        public WorkingTimeState(ITimeStateContext context, int classTimeMinutes)
        {
            this.context = context;
            this.timeLeft = new TimeLeft(classTimeMinutes, context.Options.WorkingDelayingMinutes);
            this.timeLeft.Start();
        }

        public Status Status => Status.WorkingTime;

        public string GetDescription()
        {
            return this.timeLeft.GetTimeLeft().ToString();
        }

        public void Start()
        {

        }

        public bool CanStart
        {
            get
            {
                return false;
            }
        }

        public void Delay()
        {
            this.timeLeft.Delay();
        }

        public bool CanDelay
        {
            get
            {
                return true;
            }
        }

        public void TryFinish()
        {
            if (this.timeLeft.GetTimeLeft().IsOver)
            {
                this.context.ChangeState(new WorkingFinishState(this.context));
            }
        }

        public string StartButtonText => this.context.Options.WorkingTimeStartButtonText;
        public string DelayButtonText => String.Format(this.context.Options.WorkingTimeDelayButtonText, this.context.Options.WorkingDelayingMinutes);

    }
}
